package me.spring.cloud.components.starter.oauth2.backend.handler;

import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import me.spring.cloud.common.components.response.util.CommonResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;

/**
 * @description: 登录成功处理器
 * @author: luffy
 * @create: 2018-09-17 15:35
 **/
@Slf4j
public class Oauth2LogoutSuccessHandler implements LogoutSuccessHandler {

  @Autowired
  private ObjectMapper objectMapper;

  @Override
  public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response,
      Authentication authentication) throws IOException, ServletException {
    response.setContentType("application/json;charset=UTF-8");
    response.setStatus(HttpServletResponse.SC_OK);
    response.getWriter().write(objectMapper.writeValueAsString(CommonResponseUtil.success(null)));
  }
}
